package org.example.chatservice.repository;

import org.example.chatservice.entity.ChatMessage;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ChatMessageRepository extends MongoRepository<ChatMessage, String> {
    List<ChatMessage> findByConversationIdOrderByTimestampDesc(String conversationId);
    
    @Query(value = "{ 'conversationId': ?0, 'receiverId': ?1 }", 
           update = "{ '$set': { 'isRead': true } }")
    void markMessagesAsRead(String conversationId, String receiverId);
}